package com.csw.rediscachedemo.aspect;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * 原文链接：https://blog.csdn.net/as4589sd/article/details/121867950
 */
@Component
public class RedLock {//单体形式
    @Bean(name = "RedissonClient")
    @Primary
    public static RedissonClient getRedissonClient() {//默认解锁失效时间是30s，两个时间
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://192.168.147.131:6379")
                .setPassword("123456a")
                .setTimeout(60*60*1000);//1小时连接时间
//        config.useSentinelServers().addSentinelAddress("127.0.0.1:6369", "127.0.0.1:6379", "127.0.0.1:6389").
//                setMasterName("masterName").setPassword("password").setDatabase(0);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
